package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YyAchievement;
import com.ruoyi.system.service.IYyAchievementService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生课程成绩关联Controller
 *
 * @author ruoyi
 * @date 2024-05-13
 */
@Controller
@RequestMapping("/system/achievement")
public class YyAchievementController extends BaseController
{
    private String prefix = "system/achievement";

    @Autowired
    private IYyAchievementService yyAchievementService;

    @RequiresPermissions("system:achievement:view")
    @GetMapping()
    public String achievement()
    {
        return prefix + "/achievement";
    }

    /**
     * 查询学生课程成绩关联列表
     */
    @RequiresPermissions("system:achievement:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YyAchievement yyAchievement)
    {

        yyAchievement.setUserId(getUserId());
        startPage();
        List<YyAchievement> list = yyAchievementService.selectYyAchievementList(yyAchievement);
        return getDataTable(list);
    }

    /**
     * 导出学生课程成绩关联列表
     */
    @RequiresPermissions("system:achievement:export")
    @Log(title = "学生课程成绩关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YyAchievement yyAchievement)
    {
        List<YyAchievement> list = yyAchievementService.selectYyAchievementList(yyAchievement);
        ExcelUtil<YyAchievement> util = new ExcelUtil<YyAchievement>(YyAchievement.class);
        return util.exportExcel(list, "学生课程成绩关联数据");
    }

    /**
     * 新增学生课程成绩关联
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学生课程成绩关联
     */
    @RequiresPermissions("system:achievement:add")
    @Log(title = "学生课程成绩关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YyAchievement yyAchievement)
    {
        return toAjax(yyAchievementService.insertYyAchievement(yyAchievement));
    }

    /**
     * 修改学生课程成绩关联
     */
    @RequiresPermissions("system:achievement:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        YyAchievement yyAchievement = yyAchievementService.selectYyAchievementById(id);
        mmap.put("yyAchievement", yyAchievement);
        return prefix + "/edit";
    }

    /**
     * 修改保存学生课程成绩关联
     */
    @RequiresPermissions("system:achievement:edit")
    @Log(title = "学生课程成绩关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YyAchievement yyAchievement)
    {
        return toAjax(yyAchievementService.updateYyAchievement(yyAchievement));
    }

    /**
     * 删除学生课程成绩关联
     */
    @RequiresPermissions("system:achievement:remove")
    @Log(title = "学生课程成绩关联", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(yyAchievementService.deleteYyAchievementByIds(ids));
    }
}
